
/**
** \file       ast_printelt.c
**
** \brief      this function print the prefix rule
**
** \author     Ben M'rad Hanna, Laterem Hamza, Boillot Ulysse, De Olivera
**             Guillaume and Nguyen Viet Dung
**
** \version    1.0
**
** \date       28 Novembre 2010
**
*/

#include "ast_printer.h"

int	print_prefix(s_prefix		*node,
		     int		i,
		     int		fd)
{
  int	pere = i;

  while (node != NULL)
    {
      ++i;
      print_int(i, fd);
      write(fd, " [label = \"prefix\"];\n", 21);
      print_int(pere, fd);
      write(fd, " -> ", 4);
      print_int(i, fd);
      write(fd, "\n", 1);
      i = print_redir(node->redir, i, fd);
      node = node->next;
    }
  return (i);

}

int	print_element(s_element		*node,
		      int		i,
		      int		fd)
{
  int	pere = i;

  while (node != NULL)
    {
      ++i;
      print_int(i, fd);
      write(fd, " [label = \"element\"];\n", 22);
      print_int(pere, fd);
      write(fd, " -> ", 4);
      print_int(i, fd);
      write(fd, "\n", 1);
      i = print_redir(node->redir, i, fd);
      node = node->next;
    }
  return (i);
}

int	print_cmpdlist(s_cmpdlist	*node,
		       int		i,
		       int		fd,
		       int		last)
{
  if (node != NULL)
    {
      ++last;
      print_int(last, fd);
      write(fd, " [label = \"compound list\"];\n", 28);
      print_int(i, fd);
      write(fd, " -> ", 4);
      print_int(last, fd);
      write(fd, "\n", 1);
      if (node->andor != NULL)
	last = print_andor(node->andor, last, fd);
    }
  return (last);
}

void	print_word(s_word		*node,
		   int			i,
		   int			fd)
{
  int	pere = i;

  while (node != NULL)
    {
      ++i;
      print_int(i, fd);
      write(fd, " [label = \"word\"];\n", 19);
      print_int(pere, fd);
      write(fd, " -> ", 4);
      print_int(i, fd);
      node = node->next;
    }
}

int	print_redir(s_redir		*node,
		    int			i,
		    int			fd)
{
  int	pere = i;

  while (node != NULL)
    {
      ++i;
      print_int(i, fd);
      write(fd, " [label = \"redir\"];\n", 20);
      print_int(pere, fd);
      write(fd, " -> ", 4);
      print_int(i, fd);
      write(fd, "\n", 1);
      node = node->next;
    }
  return (i);
}
